package com.yanqu.road.server.cmd.wingroom.message;

import com.yanqu.road.pb.wingroom.WingRoomProto;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.wingroom.WingRoomMessageMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2022/3/18 12:08
 */
@Cmd(code = GameProtocol.S_WING_ROOM_GET_MESSAGE_DETAIL, desc = "获取留言详情")
public class GetMessageDetailCmd extends AbstractCommand {
    private long ownerServerId;
    private long ownerUserId;
    private long messageId;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        WingRoomProto.GetMessageDetailReqMsg reqMsg = WingRoomProto.GetMessageDetailReqMsg.parseFrom(packet.getBytes());
        ownerServerId = reqMsg.getOwnerServerId();
        ownerUserId = reqMsg.getOwnerUserId();
        messageId = reqMsg.getMessageId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        //本服
        if (ownerServerId == GameServer.getInstance().getServerId()) {
            WingRoomProto.GetMessageDetailRespMsg.Builder respMsg
                    = WingRoomMessageMgr.getMessageDetailInfo(ownerUserId, messageId, GameServer.getInstance().getServerId(), player.getUserId());
            if (respMsg != null) {
                player.sendPacket(ClientProtocol.U_WING_ROOM_GET_MESSAGE_DETAIL, respMsg);
            }
            return;
        }
        //跨服
        WingRoomProto.GetMessageReqCrossMsg.Builder reqCrossMsg = WingRoomProto.GetMessageReqCrossMsg.newBuilder();
        reqCrossMsg.setMessageId(messageId);
        reqCrossMsg.setOwnerServerId(ownerServerId);
        reqCrossMsg.setOwnerUserId(ownerUserId);
        YanQuMessage message = YanQuMessageUtils.buildMessage(CrossProtocol.C_WING_ROOM_GET_MESSAGE_DETAIL, reqCrossMsg);
        player.sendPacket(message);

    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
